﻿using WpfMvvmTemplatePrismHC.Models.BindingModels;

namespace WpfMvvmTemplatePrismHC.ViewModels.Dialogs
{
    public class InquiryDialogViewModel : BindableBase, IDialogAware
    {
        /// <summary>
        /// InquiryDialogModel模型
        /// </summary>
        public InquiryDialogModel? InquiryDialogModels { get; set; }

        //关闭对话框委托
        public event Action<IDialogResult>? RequestClose;

        public DelegateCommand? YesCommand { get; set; }
        public DelegateCommand? NoCommand { get; set; }

        public string? Title => InquiryDialogModels?.Title;

        public InquiryDialogViewModel()
        {
            InquiryDialogModels = new();
            YesCommand = new DelegateCommand(Yes);
            NoCommand = new DelegateCommand(No);
        }

        private void Yes()
        {
            //传递参数字典
            DialogParameters param = new()
            {
                { "content", InquiryDialogModels?.Content }
            };

            RequestClose?.Invoke(new DialogResult(ButtonResult.Yes, param));
        }

        private void No()
        {
            RequestClose?.Invoke(new DialogResult(ButtonResult.No));
        }

        public bool CanCloseDialog()
        {
            return true;
        }

        public void OnDialogClosed()
        {
        }

        public void OnDialogOpened(IDialogParameters parameters)
        {
            InquiryDialogModels!.Content = parameters.GetValue<string>("message");
        }
    }
}